package com.xinqi.modules.user.users.third.controller.web;

import com.xinqi.common.log.asynclog.annotation.AsyncLog;
import com.xinqi.common.log.asynclog.enums.AsyncOperaType;
import com.xinqi.common.log.asynclog.enums.AsyncType;
import com.xinqi.common.satoken.utils.LoginHelper;
import com.xinqi.modules.user.third.dto.req.UserNotificationUpdateDTO;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.user.users.third.service.UserNotificationService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * APP -- 个人中心通知设置
 *
 * @version V1.0
 * @Title:
 * @ClassName: com.xinqi.modules.user.third.controller.web.UserNotificationWebController.java
 * @Description:
 * @Copyright 星齐科技（云南）有限公司 - Powered By 技术部
 * @author: yyzhen
 * @date: 2023/7/17 17:46
 */
@RestController
@RequestMapping("/web/notification")
@RequiredArgsConstructor
public class UserNotificationWebController {
    private final UserNotificationService userNotificationService;

    /**
     * 个人中心通知设置表-详情
     */
    @GetMapping("/initNotification")
    public R<UserNotificationUpdateDTO> initNotification() {
        return R.data(userNotificationService.initNotification(LoginHelper.getUserId()));
    }

    /**
     * 修改个人中心通知设置表
     */
    @AsyncLog(title = "修改个人中心通知设置", asyncType = AsyncType.USER_INFO, operatorType = AsyncOperaType.USER_NOTIFICATION)
    @PostMapping("updateNotification")
    public R<Boolean> updateNotification(@Validated @RequestBody UserNotificationUpdateDTO dto) {
        dto.setUserId(LoginHelper.getUserId());
        return R.data(userNotificationService.updateNotification(dto));
    }

}
